home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / util / misc / VMM_src.lha / VMM / MUI / memory_page.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-16  |  13.5 KB  |  470 lines

  1. #include "defs.h"
  2.  
  3. static char *Policies [4];
  4. static char *PagingDevice [4];
  5. static char *MemoryOptions [4];
  6.  
  7. static struct Hook MinMemHook,
  8.                    MaxMemHook,
  9.                    ConstructHook,
  10.                    DestructHook,
  11.                    DisplayHook,
  12.                    List2StrHook;
  13.  
  14. struct DriveEntry 
  15.   {
  16.   char name [40];
  17.   ULONG size;            /* in KB */
  18.   };
  19.  
  20. /********************************************************************/
  21.  
  22. #ifdef __GNUC__
  23. static void RaiseHook (void)
  24. #else
  25. static __saveds __asm void RaiseHook (void)
  26. #endif
  27.  
  28. {
  29. ULONG CurMinMem,
  30.       CurMaxMem;
  31.  
  32. get (SL_MinMem, MUIA_Slider_Level, &CurMinMem);
  33. get (SL_MaxMem, MUIA_Slider_Level, &CurMaxMem);
  34. if (CurMinMem > CurMaxMem)
  35.   set (SL_MaxMem, MUIA_Slider_Level, CurMinMem);
  36. }
  37.  
  38. /********************************************************************/
  39.  
  40. #ifdef __GNUC__
  41. static void LowerHook (void)
  42. #else
  43. static __saveds __asm void LowerHook (void)
  44. #endif
  45.  
  46. {
  47. ULONG CurMinMem,
  48.       CurMaxMem;
  49.  
  50. get (SL_MinMem, MUIA_Slider_Level, &CurMinMem);
  51. get (SL_MaxMem, MUIA_Slider_Level, &CurMaxMem);
  52. if (CurMinMem > CurMaxMem)
  53.   set (SL_MinMem, MUIA_Slider_Level, CurMaxMem);
  54. }
  55.  
  56. /********************************************************************/
  57.  
  58. #ifdef __GNUC__
  59. static APTR ConstructFunc (struct Hook *hook, struct DriveEntry *de)
  60. #else
  61. static __saveds __asm APTR ConstructFunc (register __a1 struct DriveEntry *de)
  62. #endif
  63.  
  64. {
  65. struct DriveEntry *new;
  66.  
  67. if ((new = AllocMem (sizeof (struct DriveEntry), MEMF_PUBLIC)) == NULL)
  68.   return (NULL);
  69.  
  70. strcpy (new->name, de->name);
  71. new->size = de->size;
  72.  
  73. return (new);
  74. }
  75.  
  76. /********************************************************************/
  77.  
  78. #ifdef __GNUC__
  79. static void DestructFunc (struct Hook *hook, struct DriveEntry *de)
  80. #else
  81. static __saveds __asm void DestructFunc (register __a1 struct DriveEntry *de)
  82. #endif
  83.  
  84. {
  85. FreeMem (de, sizeof (struct DriveEntry));
  86. }
  87.  
  88. /********************************************************************/
  89.  
  90. #ifdef __GNUC__
  91. static APTR DisplayFunc (struct Hook *hook, struct DriveEntry *de, char **array)
  92. #else
  93. static __saveds __asm LONG DisplayFunc (register __a1 struct DriveEntry *de,
  94.                                         register __a2 char **array)
  95. #endif
  96.  
  97. {
  98. static char buf [80];
  99.  
  100. if (de->size < 2048)
  101.   sprintf (buf, "\033I[6:%ld] %-6s %4ld kB", MUII_HardDisk, 
  102.            de->name, de->size);
  103. else
  104.   sprintf (buf, "\033I[6:%ld] %-6s %4ld MB", MUII_HardDisk, 
  105.            de->name, de->size / 1024);
  106.  
  107. *array++ = buf;
  108. return (0);
  109. }
  110.  
  111. /********************************************************************/
  112.  
  113. #ifdef __GNUC__
  114. static void List2StrFunc (struct Hook *hook, Object *str, Object *list)
  115. #else
  116. static __saveds __asm void List2StrFunc (register __a1 Object *str,
  117.                                          register __a2 Object *list)
  118. #endif
  119.  
  120. {
  121. struct DriveEntry *de;
  122.  
  123. DoMethod (list, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &de);
  124. if (de != NULL)
  125.   set (str, MUIA_String_Contents, de->name);
  126. }
  127.  
  128. /********************************************************************/
  129.  
  130. Object *CreateMemoryPage (void)
  131.  
  132. {
  133. InitHook (&ConstructHook, (HOOKFUNC)ConstructFunc);
  134. InitHook (&DestructHook, (HOOKFUNC)DestructFunc);
  135. InitHook (&DisplayHook, (HOOKFUNC)DisplayFunc);
  136. InitHook (&List2StrHook, (HOOKFUNC)List2StrFunc);
  137.  
  138. Policies [0] = GetVMMString (msgFixedSize);
  139. Policies [1] = GetVMMString (msgDynamic);
  140. Policies [2] = GetVMMString (msgRestrictedDynamic);
  141. Policies [3] = NULL;
  142.  
  143. PagingDevice [0] = GetVMMString (msgFile);
  144. PagingDevice [1] = GetVMMString (msgDevice);
  145. PagingDevice [2] = GetVMMString (msgPseudoPart);
  146. PagingDevice [3] = NULL;
  147.  
  148. MemoryOptions [0] = GetVMMString (msgAny);
  149. MemoryOptions [1] = GetVMMString (msgChip);
  150. MemoryOptions [2] = GetVMMString (msgFast);
  151. MemoryOptions [3] = NULL;
  152.  
  153. GR_File = PopaslObject,
  154.             MUIA_Popstring_String, ST_FileName = KeyString (0, 256, 'f'),
  155.             MUIA_Popstring_Button, PopButton (MUII_PopFile),
  156.             MUIA_Popasl_Type, ASL_FileRequest,
  157.             ASLFR_TitleText, GetVMMString (msgSelectFile),
  158.           End;
  159.  
  160. DiskList = ListObject, 
  161.              MUIA_List_ConstructHook, &ConstructHook,
  162.              MUIA_List_DestructHook, &DestructHook,
  163.              MUIA_List_DisplayHook, &DisplayHook,
  164.            End;
  165.  
  166. PO_Disks = PopobjectObject,
  167.              MUIA_Popobject_Object, LV_Disks =
  168.                ListviewObject,
  169.                  MUIA_Listview_List, DiskList,
  170.                  MUIA_Frame, MUIV_Frame_InputList,
  171.                  MUIA_HelpNode, "SwapMedium_Gadget",
  172.                End,
  173.              MUIA_Popstring_String, ST_PartName = KeyString (0, 60, 'n'),
  174.              MUIA_Popstring_Button, PopButton (MUII_PopUp),
  175.              MUIA_Popobject_ObjStrHook, &List2StrHook,
  176.            End;
  177.  
  178.  
  179.  
  180. GR_Memory = ColGroup (3),
  181.               MUIA_Group_SameWidth, TRUE,
  182.               MUIA_HelpNode, "Memory_Settings",
  183.  
  184.               Child, Label (GetVMMString (msgPagingMemory)),
  185.               Child, Label (GetVMMString (msgMemType)),
  186.               Child, HVSpace,
  187.  
  188.               Child, CY_Policy   = 
  189.                 CycleObject, 
  190.                   MUIA_Cycle_Entries, Policies,
  191.                   MUIA_HelpNode, "MemType_Gadget",
  192.                 End,
  193.               Child, CY_MemFlags = 
  194.                 CycleObject,
  195.                   MUIA_Cycle_Entries, MemoryOptions,
  196.                   MUIA_HelpNode, "MemFlags_Gadget",
  197.                 End,
  198.               Child, CY_Device   = 
  199.                 CycleObject,
  200.                   MUIA_Cycle_Entries, PagingDevice,
  201.                   MUIA_HelpNode, "SwapMedium_Gadget",
  202.                 End,
  203.  
  204.               Child, VSpace (0),
  205.               Child, VSpace (0),
  206.               Child, VSpace (0),
  207.  
  208.               Child, Label (GetVMMString (msgMinMem)),
  209.               Child, Label (GetVMMString (msgWriteBuffer)),
  210.               Child, VSpace (0),
  211.  
  212.               Child, SL_MinMem =
  213.                 SliderObject, 
  214.                   MUIA_Slider_Min, 1,
  215.                   MUIA_Slider_Max, 40,
  216.                   MUIA_Slider_Level, 1,
  217.                   MUIA_Slider_Quiet, TRUE,
  218.                   MUIA_FixHeight, TRUE,
  219.                   MUIA_HelpNode, "MemType_Gadget",
  220.                 End,
  221.               Child, SL_Buffer =
  222.                 SliderObject,
  223.                   MUIA_Slider_Min, 0,
  224.                   MUIA_Slider_Max, 100,
  225.                   MUIA_Slider_Level, 10,
  226.                   MUIA_Slider_Quiet, TRUE,
  227.                   MUIA_FixHeight, TRUE,
  228.                   MUIA_HelpNode, "WriteBuffer_Gadget",
  229.                 End,
  230.               Child, GR_DevName =
  231.                 PageGroup, 
  232.                   Child, PO_Disks,
  233.                   Child, GR_File,
  234.                   MUIA_Group_ActivePage, 1,
  235.                   MUIA_HelpNode, "SwapMedium_Gadget",
  236.                 End,
  237.  
  238.               Child, TX_MinMem =
  239.                 TextObject,
  240.                   MUIA_Text_PreParse, "\033c",
  241.                   MUIA_Text_Contents, "100 KByte",
  242.                 End,
  243.               Child, TX_Buffer =
  244.                 TextObject,
  245.                   MUIA_Text_PreParse, "\033c",
  246.                   MUIA_Text_Contents, "100 KByte",
  247.                 End,
  248.               Child, HVSpace,
  249.  
  250.               Child, VSpace (0),
  251.               Child, VSpace (0),
  252.               Child, VSpace (0),
  253.  
  254.               Child, Label (GetVMMString (msgMaxMem)),
  255.               Child, Label (GetVMMString (msgPrio)),
  256.               Child, Label (GetVMMString (msgFileSize)),
  257.  
  258.               Child, SL_MaxMem =
  259.                 SliderObject, 
  260.                   MUIA_Slider_Min, 1,
  261.                   MUIA_Slider_Max, 40,
  262.                   MUIA_Slider_Level, 1,
  263.                   MUIA_Slider_Quiet, TRUE,
  264.                   MUIA_Disabled, TRUE,
  265.                   MUIA_FixHeight, TRUE,
  266.                   MUIA_HelpNode, "MemType_Gadget",
  267.                 End,
  268.               Child, SL_Prio =
  269.                 SliderObject,
  270.                   MUIA_Slider_Min, -128,
  271.                   MUIA_Slider_Max, 127,
  272.                   MUIA_Slider_Level, 40,
  273.                   MUIA_Slider_Quiet, TRUE,
  274.                   MUIA_FixHeight, TRUE,
  275.                   MUIA_HelpNode, "MemPri_Gadget",
  276.                 End,
  277.               Child, SL_FileSize =
  278.                 SliderObject,
  279.                   MUIA_Slider_Min, 1,
  280.                   MUIA_Slider_Max, NUM_PTR_TABLES * POINTERS_PER_TABLE * PAGES_PER_TABLE * PAGESIZE
  281.                                    / (1024 * 1024),
  282.                   MUIA_Slider_Level, 1,
  283.                   MUIA_Slider_Quiet, TRUE,
  284.                   MUIA_FixHeight, TRUE,
  285.                   MUIA_Disabled, FALSE,
  286.                   MUIA_HelpNode, "FileSize_Gadget",
  287.                 End,
  288.               
  289.               Child, TX_MaxMem =
  290.                 TextObject,
  291.                   MUIA_Text_PreParse, "\033c",
  292.                   MUIA_Text_Contents, "100 KByte",
  293.                 End,
  294.               Child, TX_Prio =
  295.                 TextObject,
  296.                   MUIA_Text_PreParse, "\033c",
  297.                   MUIA_Text_Contents, "40",
  298.                 End,
  299.               Child, TX_FileSize =
  300.                 TextObject,
  301.                   MUIA_Text_PreParse, "\033c",
  302.                   MUIA_Text_Contents, "1 MByte",
  303.                 End,
  304.             End;
  305.               
  306. DoMethod (SL_MinMem, MUIM_Notify, 
  307.           MUIA_Slider_Level, MUIV_EveryTime,
  308.           TX_MinMem,
  309.           4,
  310.           MUIM_SetAsString, MUIA_Text_Contents, "%ld00 KByte", MUIV_TriggerValue);
  311.  
  312. DoMethod (SL_MaxMem, MUIM_Notify, 
  313.           MUIA_Slider_Level, MUIV_EveryTime,
  314.           TX_MaxMem,
  315.           4,
  316.           MUIM_SetAsString, MUIA_Text_Contents, "%ld00 KByte", MUIV_TriggerValue);
  317.  
  318. DoMethod (CY_Policy, MUIM_Notify,
  319.           MUIA_Cycle_Active, MT_FIXED, 
  320.           SL_MinMem,
  321.           3,
  322.           MUIM_Set, MUIA_Disabled, FALSE);
  323. DoMethod (CY_Policy, MUIM_Notify,
  324.           MUIA_Cycle_Active, MT_FIXED, 
  325.           SL_MaxMem,
  326.           3,
  327.           MUIM_Set, MUIA_Disabled, TRUE);
  328. DoMethod (CY_Policy, MUIM_Notify,
  329.           MUIA_Cycle_Active, MT_DYNAMIC, 
  330.           SL_MinMem,
  331.           3,
  332.           MUIM_Set, MUIA_Disabled, TRUE);
  333. DoMethod (CY_Policy, MUIM_Notify,
  334.           MUIA_Cycle_Active, MT_DYNAMIC, 
  335.           SL_MaxMem,
  336.           3,
  337.           MUIM_Set, MUIA_Disabled, TRUE);
  338. DoMethod (CY_Policy, MUIM_Notify,
  339.           MUIA_Cycle_Active, MT_RESTRICTED, 
  340.           SL_MinMem,
  341.           3,
  342.           MUIM_Set, MUIA_Disabled, FALSE);
  343. DoMethod (CY_Policy, MUIM_Notify,
  344.           MUIA_Cycle_Active, MT_RESTRICTED, 
  345.           SL_MaxMem,
  346.           3,
  347.           MUIM_Set, MUIA_Disabled, FALSE);
  348.  
  349. DoMethod (SL_Buffer, MUIM_Notify, 
  350.           MUIA_Slider_Level, MUIV_EveryTime,
  351.           TX_Buffer,
  352.           4,
  353.           MUIM_SetAsString, MUIA_Text_Contents, "%ld0 KByte", MUIV_TriggerValue);
  354.  
  355. DoMethod (SL_Prio, MUIM_Notify, 
  356.           MUIA_Slider_Level, MUIV_EveryTime,
  357.           TX_Prio,
  358.           4,
  359.           MUIM_SetAsString, MUIA_Text_Contents, "%ld", MUIV_TriggerValue);
  360.  
  361. DoMethod (LV_Disks, MUIM_Notify, 
  362.           MUIA_Listview_DoubleClick, TRUE,
  363.           PO_Disks, 2, MUIM_Popstring_Close, TRUE);
  364.  
  365. DoMethod (SL_FileSize, MUIM_Notify, 
  366.           MUIA_Slider_Level, MUIV_EveryTime,
  367.           TX_FileSize,
  368.           4,
  369.           MUIM_SetAsString, MUIA_Text_Contents, "%ld MByte", MUIV_TriggerValue);
  370.  
  371. DoMethod (CY_Device, MUIM_Notify,
  372.           MUIA_Cycle_Active, PD_PART,
  373.           GR_DevName,
  374.           3,
  375.           MUIM_Set, MUIA_Group_ActivePage, 0);
  376.  
  377. DoMethod (CY_Device, MUIM_Notify,
  378.           MUIA_Cycle_Active, PD_FILE,
  379.           GR_DevName,
  380.           3,
  381.           MUIM_Set, MUIA_Group_ActivePage, 1);
  382.  
  383. DoMethod (CY_Device, MUIM_Notify,
  384.           MUIA_Cycle_Active, PD_PSEUDOPART,
  385.           GR_DevName,
  386.           3,
  387.           MUIM_Set, MUIA_Group_ActivePage, 1);
  388.  
  389. DoMethod (CY_Device, MUIM_Notify,
  390.           MUIA_Cycle_Active, PD_PART,
  391.           SL_FileSize,
  392.           3,
  393.           MUIM_Set, MUIA_Disabled, TRUE);
  394.  
  395. DoMethod (CY_Device, MUIM_Notify,
  396.           MUIA_Cycle_Active, PD_FILE,
  397.           SL_FileSize,
  398.           3,
  399.           MUIM_Set, MUIA_Disabled, FALSE);
  400.  
  401. DoMethod (CY_Device, MUIM_Notify,
  402.           MUIA_Cycle_Active, PD_PSEUDOPART,
  403.           SL_FileSize,
  404.           3,
  405.           MUIM_Set, MUIA_Disabled, FALSE);
  406.  
  407. InitHook (&MinMemHook, (HOOKFUNC)RaiseHook);
  408. InitHook (&MaxMemHook, (HOOKFUNC)LowerHook);
  409.  
  410. DoMethod (SL_MinMem, MUIM_Notify,
  411.           MUIA_Slider_Level, MUIV_EveryTime,
  412.           SL_MinMem,
  413.           2,
  414.           MUIM_CallHook, &MinMemHook);
  415.  
  416. DoMethod (SL_MaxMem, MUIM_Notify,
  417.           MUIA_Slider_Level, MUIV_EveryTime,
  418.           SL_MaxMem,
  419.           2,
  420.           MUIM_CallHook, &MaxMemHook);
  421.           
  422. return (GR_Memory);
  423. }
  424.  
  425. /***********************************************************************/
  426.  
  427. void HandleDiskPopup (void)
  428.  
  429. {
  430. ULONG num_entries;
  431. char *DriveName;
  432. int length;
  433. struct DosList *dl;
  434. struct FileSysStartupMsg *fssm;
  435. struct DosEnvec *de;
  436. static struct DriveEntry ThisDrive;
  437.  
  438. set (DiskList, MUIA_List_Quiet, TRUE);
  439. get (DiskList, MUIA_List_Entries, &num_entries);
  440.  
  441. if (num_entries == 0)
  442.   {
  443.   dl = LockDosList (LDF_DEVICES | LDF_WRITE);
  444.  
  445.   while ((dl = NextDosEntry (dl, LDF_DEVICES | LDF_WRITE)) != NULL)
  446.     {
  447.     DriveName = (char*)(BADDR (dl->dol_Name));
  448.     length = *DriveName++;
  449.     fssm = BADDR (dl->dol_misc.dol_handler.dol_Startup);
  450.     if (TypeOfMem (fssm) != NULL)
  451.       {
  452.       de = (struct DosEnvec*) BADDR (fssm->fssm_Environ);
  453.       if ((TypeOfMem (de) != NULL) && de->de_SizeBlock == 128L)
  454.         {
  455.         strncpy (ThisDrive.name, DriveName, length);
  456.         ThisDrive.name [length] = 0;
  457.         ThisDrive.size = de->de_Surfaces * de->de_BlocksPerTrack * 
  458.                          (de->de_HighCyl - de->de_LowCyl + 1) / 2;
  459.         DoMethod (DiskList, MUIM_List_InsertSingle, &ThisDrive,
  460.                   MUIV_List_Insert_Bottom);
  461.         }
  462.       }
  463.     }
  464.  
  465.   UnLockDosList (LDF_DEVICES | LDF_WRITE);
  466.   }
  467.  
  468. set (DiskList, MUIA_List_Quiet, FALSE);
  469. }
  470.